package com.zhf.testpool;

import com.zhf.utils.DBCPUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @Author: ZhaoHuanfeng
 * @Date: 2020/9/24 20:57
 */
public class TestDBCP {
    /**
     * 测试DBCP连接池
     */
    public static void main(String[] args) throws SQLException {
        //从连接池获取连接
        Connection connection = DBCPUtils.getConnection();

        //获取语句执行的statement对象
        Statement statement = connection.createStatement();

        //查询所有员工姓名
        String sql="select ename from employee";
        ResultSet resultSet = statement.executeQuery(sql);

        //处理结果集
        while (resultSet.next()){
            String ename=resultSet.getString("ename");
            System.out.println("ename:"+ename);
        }

        //释放资源
        DBCPUtils.close(connection,statement,resultSet);
    }
}
